<template>
    <div style="height:710px;overflow:auto;" class="aeProj">
        <div class="form-box">
            <el-form ref="form" :model="form" label-width="160px" label-position="left">
                <el-form-item label="名称">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>               
                <el-form-item label="类型">
                    <el-select v-model="type" @change="typeChange()">
                        <el-option v-for="item in items" :key="item.value" :label="item.name" :value="item.name"></el-option>
                    </el-select>
                </el-form-item>
                            
                <el-form-item label="建设必要性" >
                    <el-input v-model="form.consNecessity"></el-input>
                </el-form-item>                          
                <el-form-item label="建设起始年月" >
                    <el-date-picker  type="month"  v-model="consStartYear" placeholder="选择日期" class="dateWidth" value-format="yyyy/MM/dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>        
                <el-form-item label="建设终止年月" >
                    <el-date-picker  type="month"  v-model="consEndYear" placeholder="选择日期" class="dateWidth" value-format="yyyy/MM/dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>                        
                <el-form-item label="建设内容">
                    <el-input type="textarea" row="4" v-model="form.consContent"></el-input>
                    <div class="redWord">(建设规模及主要建设内容栏按规划环保局审查通过的方案项目概况为准，如方案未审查通过，以最新方案内容为准)</div>
                </el-form-item>
                <el-form-item label="建设地点">
                    <el-input v-model="form.consLocation"></el-input>
                    <div class="redWord">(建设地点填写地块编号，如无地块编号用文字说明具体位置)</div>
                </el-form-item>                  
                <el-form-item label="建设地点X坐标"  >
                    <el-input v-model="form.consLocationSmx" ></el-input>
                </el-form-item>         
                <el-form-item label="建设地点Y坐标" >
                    <el-input v-model="form.consLocationSmy"></el-input>
                </el-form-item>     
                <div class="select-map">
                    <base-map  :lat="form.consLocationSmy" :lng="form.consLocationSmx"  module="manager" v-on:getPoint="getPoint"></base-map>
                </div>
                <el-form-item label="项目审批单位" >
                    <el-select v-model="form.projExaminationOrg" @change="orgChange()" v-if="isAdmin">
                        <el-option v-for="item in projExaminationOrgs" :key="item" :label="item" :value="item"></el-option>
                    </el-select>
                    <el-input v-model="projDepartment" :disabled="true" v-else></el-input>
                </el-form-item>
                <el-form-item label="项目责任单位" >
                    <el-input v-model="form.projResponsibleOrg"></el-input>
                </el-form-item>
                <el-form-item label="项目实施单位" >
                    <el-input v-model="form.projImplementOrg"></el-input>
                </el-form-item>
                <el-form-item label="分管领导/企业法人" >
                    <el-input v-model="form.businessEntity"></el-input>
                </el-form-item>
                <el-form-item label="项目部门负责人" >
                    <el-input v-model="form.projDepartLeader"></el-input>
                </el-form-item>
                <el-form-item label="项目负责人" >
                    <el-input v-model="form.projLeader"></el-input>
                </el-form-item>
                <el-form-item label="项目总监" >
                    <el-input v-model="form.director"></el-input>
                </el-form-item>
                <el-form-item label="项目经理" >
                    <el-input v-model="form.projManager"></el-input>
                </el-form-item>
                <el-form-item label="建设进展阶段" >
                    <el-input v-model="form.constructionEvolve"></el-input>
                </el-form-item>                 
                <el-form-item label="预计开复工时间" >
                    <el-date-picker  type="date"  v-model="planStartWorkTime" placeholder="选择日期" class="dateWidth" value-format="yyyy/MM/dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>    
                    
                <el-form-item label="中标时间" >
                    <el-date-picker  type="date"  v-model="winBidTime" placeholder="选择日期" class="dateWidth" value-format="yyyy/MM/dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>              
                <el-form-item label="实际开复工时间" >
                    <el-date-picker  type="date"  v-model="realStartWorkTime" placeholder="选择日期" class="dateWidth" value-format="yyyy/MM/dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>
                      
                <el-form-item label="计划竣工时间" >
                    <el-date-picker  type="date"  v-model="planCompleteTime" placeholder="选择日期" class="dateWidth" value-format="yyyy/MM/dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>                 
                <el-form-item label="前期手续办理情况">
                    <el-input v-model="form.procedures"></el-input>
                    <div class="redWord">(填写经发、规划、国土、环保、住建等主要手续办理情况，概预算情况)</div>
                </el-form-item>
                <el-form-item label="存在问题(市级)" >
                    <el-input v-model="form.problemShi"></el-input>
                </el-form-item>
                <el-form-item label="存在问题(管委会)" >
                    <el-input v-model="form.problemGWH"></el-input>
                </el-form-item>
                <el-form-item label="是否入统">
                    <el-select v-model="form.isStatistics">
                        <el-option v-for="isStatistic in isStatistics" :key="isStatistic.value" :label="isStatistic.name" :value="isStatistic.value"></el-option>
                    </el-select>
                </el-form-item>          
                <el-form-item label="立项总投资(可研)(万元)">
                <el-input v-model="form.projInvestment" type="number"></el-input>
                </el-form-item>
            
                <el-form-item label="立项总投资(初设)(万元)" >
                    <el-input v-model="form.projInvestmentFirstFound" type="number"></el-input>
                </el-form-item>            
               <el-form-item label="投资备注">
                    <el-input v-model="form.investmentNote"></el-input>
                    <div class="redWord">(投资备注填写是否包含土地费或其它情况)</div>
                </el-form-item>              
                <el-form-item label="土地费用(万元)" >
                <el-input v-model="form.landCost" type="number"></el-input>
                </el-form-item>
            
                <el-form-item label="实际总投资(估算)(万元)">
                    <el-input v-model="form.realInvestment" type="number"></el-input>
                    <div class="redWord">(实际总投资(估算）由经发局估算)</div>
                </el-form-item>         
                <el-form-item label="备注" >
                    <el-input v-model="form.notes"></el-input>
                </el-form-item>
                <!--<el-form-item label="填表说明" label-width="80px" >
                    <ul>
                        <li v-for="item in textarea" :key="item">{{item}}</li>
                    </ul>
                </el-form-item>-->
                    <div class="commit-btn">
                        <el-button type="primary"  @click="submit()">提交</el-button>
                    </div>
                
            </el-form>
        </div>
    </div>
</template>

<script>
    import baseMap from "../common/Map.vue";
    import date_formate from "../tool/Global/dateutil.js";
    import {projectType,projectProgress} from "../tool/Global/app-config.js";
    import {queryProjectdetailByPkid,updateProjectdetail,addProjectDetail} from "../tool/Global/app-mgr.js";
    //import jquery from "../tool/Global/jquery-1.10.2.min.js";
    export default {
        components:{
            baseMap
        },
        props: ['pkid','projDepartmentID','projDepartment','projCreatePersonID','projCreatePerson',"isAdmin"],
        data: function(){
            return {
                isStatistics:[
                    {
                        value:1,
                        name:"是"
                    },
                    {
                        value:0,
                        name:"否"
                    }
                ],
                //textarea:YanAnAPP.tiaobiao,
                projectProgress:projectProgress,
                items:projectType,
                form:{
                    name:"",
                    projType:"",
                    consNecessity:"",
                    consLocation:"",
                    consContent:"",
                    consLocationSmx:"",
                    consLocationSmy:"",
                    projExaminationOrg:"",
                    projResponsibleOrg:"",
                    projImplementOrg:"",
                    businessEntity:"",
                    projDepartLeader:"",
                    projLeader:"",
                    director:"",
                    projManager:"",
                    constructionEvolve:"",
                    procedures:"",
                    problemShi:"",
                    problemGWH:"",
                    isStatistics:"",
                    projInvestment:"",
                    projInvestmentFirstFound:"",
                    realInvestment:"",
                    landCost:"",
                    investmentNote:"",
                    notes:"",
                    projDepartmentID:"",
                    projDepartment:"",
                    projCreatePersonID:"",
                    projCreatePerson:"",
                    currentStage:"",
                },
                consStartYear:"",
                consEndYear:"",
                planStartWorkTime:"",
                winBidTime:"",
                realStartWorkTime:"",
                planCompleteTime:"",
                type:"",
                projExaminationOrgs:YanAnAPP.projExaminationOrgS
            }
        },
        mounted:function(){
            let ref = this;
            this.$nextTick(function () {
                ref.form.projDepartmentID = ref.projDepartmentID;
                ref.form.projDepartment = ref.projDepartment;
                ref.form.projCreatePersonID = ref.projCreatePersonID;
                ref.form.projCreatePerson = ref.projCreatePerson;
                if(ref.pkid){
                    ref.form.pkid = ref.pkid;
                    queryProjectdetailByPkid(ref.pkid).then(function(result){
                        if(result.data.success){
                            let data = result.data.data;
                            for(var key in ref.form){
                                ref.form[key] = data[key]!=null?data[key]:'';
                            }
                            //ref.progress = ref.form.currentStage?ref.projectProgress[ ref.form.currentStage-1].name:'';
                            ref.consStartYear = data.consStartYear?date_formate.format(new Date(data.consStartYear),"yyyy/MM/dd hh:mm:ss"):'';
                            ref.consEndYear = data.consEndYear?date_formate.format(new Date(data.consEndYear),"yyyy/MM/dd hh:mm:ss"):'';
                            ref.planStartWorkTime = data.planStartWorkTime?date_formate.format(new Date(data.planStartWorkTime),"yyyy/MM/dd hh:mm:ss"):'';
                            ref.winBidTime = data.winBidTime?date_formate.format(new Date(data.winBidTime),"yyyy/MM/dd hh:mm:ss"):'';
                            ref.realStartWorkTime = data.realStartWorkTime?date_formate.format(new Date(data.realStartWorkTime),"yyyy/MM/dd hh:mm:ss"):'';
                            ref.planCompleteTime = data.planCompleteTime?date_formate.format(new Date(data.planCompleteTime),"yyyy/MM/dd hh:mm:ss"):'';
                        }
                    })
                }
            })
        },
        methods:{
            submit(){
                let ref = this;
                if(!this.isAdmin){
                    this.form.projExaminationOrg = this.projDepartment;
                }
                var data = {
                    projectDetail:JSON.stringify(this.form),
                    consStartYear:this.consStartYear,
                    consEndYear:this.consEndYear,
                    planStartWorkTime:this.planStartWorkTime,
                    winBidTime:this.winBidTime,
                    realStartWorkTime:this.realStartWorkTime,
                    planCompleteTime:this.planCompleteTime

                }
                let params = new URLSearchParams()
                for (var key in data) {
                    params.append(key, data[key])
                }
                if(this.pkid){
                    /*$.ajax({
                        url:this.GLOBAL.projectDetailUrl,
                        type:"put",
                        data:data,
                        success:function(result){

                        }
                    })*/
                    updateProjectdetail(params).then(function(result){
                        if(result.data.success){
                            ref.$message({message:"更新成功",type:'success'});
                            ref.$emit("listenClose");
                        }else{
                            ref.$message.error(result.data.message);
                        }
                    })
                }else{
                    addProjectDetail(params).then(function(result){
                        if(result.data.success){
                            ref.$message({message:"添加成功",type:'success'});
                            ref.$emit("listenClose");
                        }else{
                            ref.$message.error(result.data.message);
                        }
                    })
                }
            },
            typeChange(){
                for(var i=0;i<this.items.length;i++){
                    if(this.type == this.items[i].name){
                        this.form.projType = this.items[i].value;
                        break;
                    }
                }
            },
            getPoint(point){
                this.form.consLocationSmx = point.lng;
                this.form.consLocationSmy = point.lat;
            }
        }
    }
</script>

<style scoped>
    .dateWidth{
        width:150px;
    }
    .commit-btn{
        text-align: center;
    }
    .select-map{
        width: 100%;
        height: 340px;
        border-radius: 3px;
        border: 1px solid #dad8d8;
        margin-bottom:15px;
    }
    ul{
        list-style-type: none;
        color:red;
    }
</style>
